package com.huatai.bi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.bi.entity.FilterConditionEntity;
import com.huatai.bi.mapper.FilterConditionMapper;
import com.huatai.bi.service.FilterConditionService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FilterConditionServiceImpl extends ServiceImpl<FilterConditionMapper, FilterConditionEntity> implements FilterConditionService {

    public Map get(){
        Map<String,List<FilterConditionEntity>> map = new HashMap<>();
        LambdaQueryWrapper<FilterConditionEntity> qw = Wrappers.lambdaQuery();
        qw.orderByAsc(FilterConditionEntity::getType,FilterConditionEntity::getSort);
        List<FilterConditionEntity> list = list(qw);
        list.stream().forEach(item -> {
            if(!map.containsKey(item.getType())){
                map.put(item.getType(),new ArrayList());
            }
            map.get(item.getType()).add(item);
        });
        return map;
    }
}
